<template>
  <div class="top-bar">
    <div class="content-legend-jt">
      <div
        v-for="(item, index) in currentTabData.levels"
        :key="index"
        class="color"
        :style="{ backgroundColor: currentTabData.color[index] }"
      >
        {{ item }}
      </div>
    </div>
    <div class="location" @click="initCamera">
      <img src="../images/pos.png" alt="" />
    </div>
    <div class="zoom">
      <div :class="['state-switch', isLaunch ? 'state-active' : '']">
        <div
          :class="['state', isState == 'wx' ? 'stateA' : '']"
          @click="handleChangeMapStyle('wx')"
        >
          <img src="../images/map1.png" alt="" />
        </div>
        <div
          :class="['state', isState == 'xz' ? 'stateA' : '']"
          @click="handleChangeMapStyle('xz')"
        >
          <img src="../images/map2.png" alt="" />
        </div>
        <img v-if="!isLaunch" @click="launch" src="../images/open.png" alt="" />
        <img v-if="isLaunch" @click="launch" src="../images/put.png" alt="" />
      </div>
      <div class="zoom-box">
        <div @click="enlarge">
          <img src="../images/jia.png" alt="" />
        </div>
        <div class="line"></div>
        <div @click="narrow">
          <img src="../images/jian.png" alt="" />
        </div>
      </div>
    </div>
    <div class="position-wrap">
      <div class="position">
        <p>经度：{{ lng }}</p>
        <p>纬度：{{ lat }}</p>
      </div>
      <div class="size">
        {{ baseLeafletMapStore.kilometre }}
        <img src="../images/size.png" alt="" />
      </div>
    </div>
  </div>
</template>

<script setup lang="ts">
import * as L from 'leaflet'
import { createTileLayer } from '@quickearth/leaflet'
import { predefinedImageTiles } from '@quickearth/core'
import { useTrafficStore } from '@/pages/traffic/store/store'
import { useBaseLeafletMapStore } from '@/store/modules/baseLeafletMap'
import yulinSideGeojson from '@/assets/data/yulin-side.json'
import yulinGeojson from '@/assets/data/yulin.json'
const trafficStore = useTrafficStore()
const baseLeafletMapStore = useBaseLeafletMapStore()
const currentTabData = computed(() => trafficStore.currentTabData)

const props = defineProps({
  colorList: {
    type: Array,
    default: () => {
      return [
        '#acefa4 0%',
        '#4bc63f 25%',
        '#3bd2ff 43%',
        '#0401e0 62%',
        '#ed24f4 78%',
        '#6d1341 100%'
      ]
    }
  }
})

const lng = ref(0)
const lat = ref(0)
useEventBus('currentMapPositionLatLng').on((lngData, latData) => {
  lng.value = lngData
  lat.value = latData
})

const tabsList = [
  {
    label: '综合监测',
    path: 'zhjc'
  }
]
//放大
const enlarge = () => {
  useEventBus('handleEnlarge').emit()
}
//缩小
const narrow = () => {
  useEventBus('handleNarrow').emit()
}
//展开
const isLaunch = ref(false)
const launch = () => {
  isLaunch.value = !isLaunch.value
}
const isState = ref('wx')
// 图层处理
const handleChangeMapStyle = val => {
  isState.value = val
  switch (val) {
    case 'wx':
      useEventBus('handleRemoveLayer').emit('tdtNormal')
      const tdtNormalTileLayer = L.tileLayer(
        'http://172.18.77.23:80/sfzxGis/tdtSatellite/{z}/{x}/{y}.jpg'
      )
      useEventBus('handleAddLayer').emit(tdtNormalTileLayer, 'tdtSatellite')
      break
    case 'xz':
      useEventBus('handleRemoveLayer').emit('tdtSatellite')
      const tdtSatelliteTileLayer = L.tileLayer(
        'http://172.18.77.23:80/sfzxGis/tdtNormal/{z}/{x}/{y}.jpg'
      )
      useEventBus('handleAddLayer').emit(tdtSatelliteTileLayer, 'tdtNormal')
      break
  }
}
const initCamera = () => {
  useEventBus('handleInitCameraPosition').emit()
  useEventBus('handleRemoveLayer').emit('taiyuanqxWhite')
  useEventBus('handleRemoveLayer').emit('taiyuanshiWhite')
  useEventBus('handleRemoveLayer').emit('yulinWhite')
  useEventBus('handleRemoveLayer').emit('yulinSideWhite')
  trafficStore.componentsVisible.labels = 'all'
  useEventBus('handleInitLayer').emit(yulinGeojson, 'yulinWhite')
}
onMounted(() => {
  handleChangeMapStyle(isState.value)
})
</script>

<style scoped lang="scss">
.content-legend-jt {
  position: absolute;
  right: 60px;
  bottom: 123px;
  z-index: 1200;
  box-sizing: border-box;
  background: #f8f8f8;
  display: flex;
  justify-content: center;
  align-items: center;
  border-radius: 10px;
  .color {
    min-width: 85px;
    height: 20px;
    line-height: 20px;
    color: #fff;
    background-color: #fff;
    padding: 2px 15px;
    text-align: center;
    &:first-child {
      border-radius: 10px 0 0 10px;
    }
    &:last-child {
      border-radius: 0 10px 10px 0;
    }
  }
}
// .top-bar {
//   position: absolute;
//   bottom: 0;
//   right: 0;
//   width: 20%;
//   height: 600px;
//   background-color: transparent;
//   z-index: 1200;
//   display: flex;
//   align-items: center;
//   justify-content: space-between;
//   padding: 0 10px;
//   box-sizing: border-box;
.color-legend {
  width: 21px;
  height: 400px;
  z-index: 1200;
  // background: linear-gradient(
  //   180deg,
  //   #acefa4 0%,
  //   #4bc63f 25%,
  //   #3bd2ff 43%,
  //   #0401e0 62%,
  //   #ed24f4 78%,
  //   #6d1341 100%
  // );
  border-radius: 19px 19px 19px 19px;
  position: absolute;
  right: 21px;
  bottom: 157px;
}
.location {
  width: 30px;
  height: 30px;
  border-radius: 50%;
  position: absolute;
  right: 17px;
  bottom: 119px;
  background: rgba(0, 17, 46, 0.66);
  box-shadow: 0px 0px 10px 1px rgba(0, 0, 0, 0.47);
  border: 1px solid rgba(255, 255, 255, 0.23);
  display: flex;
  justify-content: center;
  align-items: center;
  z-index: 1200;
  cursor: pointer;
  img {
    width: 16px;
    height: 16px;
  }
}
.zoom {
  width: 100%;
  min-height: 60px;
  display: flex;
  justify-content: flex-end;
  align-items: end;
  position: absolute;
  right: 17px;
  bottom: 50px;
  z-index: 1200;
  .zoom-box {
    width: 30px;
    height: 60px;
    background: rgba(0, 17, 46, 0.66);
    box-shadow: 0px 0px 10px 1px rgba(0, 0, 0, 0.47);
    // border-radius: 15px 15px 15px 15px;
    border: 1px solid rgba(255, 255, 255, 0.23);
    padding: 8px 5px;
    box-sizing: border-box;
    div:first-child {
      width: 100%;
      height: 49%;
      display: flex;
      justify-content: center;
      align-items: start;
      cursor: pointer;
      img {
        width: 14px;
        height: 14px;
      }
    }
    div:last-child {
      width: 100%;
      height: 40%;
      display: flex;
      justify-content: center;
      align-items: end;
      cursor: pointer;
      img {
        width: 14px;
        height: 1.75px;
      }
    }

    .line {
      width: 100%;
      height: 1px;
      background-color: #fff;
      opacity: 0.18;
    }
  }
  .state-switch {
    width: 151px;
    height: 60px;
    background: rgba(10, 146, 253, 0.09);
    box-shadow: 0px 0px 8px 1px #0a92fd;
    border-radius: 6px 6px 6px 6px;
    border: 1px solid #0a92fd;
    margin-right: 18px;
    padding: 9px 5px;
    box-sizing: border-box;
    display: flex;
    align-items: center;
    justify-content: space-around;
    .state {
      width: 44px;
      height: 44px;
      background: #ffffff;
      border-radius: 22px 22px 22px 22px;
      border: 1px solid #707070;
      margin-right: 10px;
      cursor: pointer;
      img {
        width: 100%;
        height: 100%;
        border-radius: 50%;
      }
    }
    .stateA {
      border: 1px solid #00ccff;
    }
    img {
      width: 14px;
      height: 14px;
      margin-right: 0px;
      cursor: pointer;
    }
  }
  .state-active {
    width: 244px;
    height: 122px;
    background: rgba(0, 13, 35, 0.76);
    box-shadow: 0px 0px 6px 1px rgba(0, 204, 255, 0.77),
      inset 0px 0px 14px 1px #00ccff;
    border-radius: 4px 4px 4px 4px;
    border: 1px solid #2c96cd;
    padding: 9px 5px;
    .state {
      width: 80px;
      height: 80px;
      background: #ffffff;
      border-radius: 10px 10px 10px 10px;
      border: 1px solid #707070;
    }
    .stateA {
      border: 1px solid #00ccff;
    }
  }
}
.position-wrap {
  position: absolute;
  bottom: 6px;
  right: 17px;
  display: flex;
  justify-content: flex-end;
  align-items: center;
  z-index: 1200;
  .position {
    display: flex;
    align-items: center;
    font-size: 14px;

    p {
      // width: 150px;
      margin-right: 10px;
      color: #ffffff;
    }
  }
  .size {
    width: 80px;
    height: 30px;
    background: rgba(0, 17, 46, 0.66);
    box-shadow: 0px 0px 10px 1px rgba(0, 0, 0, 0.47);
    border-radius: 15px 15px 15px 15px;
    border: 1px solid rgba(255, 255, 255, 0.23);
    font-size: 12px;
    color: #ffffff;
    line-height: 1.6;
    text-align: center;
    position: relative;
    img {
      width: 50px;
      height: 8px;
      position: absolute;
      bottom: 5px;
      left: 50%;
      transform: translateX(-50%);
    }
  }
}
</style>
